const {HydSDK} = require("../HYDSDK/TTHSDK");
const GlobalData = require("../HYDSDK/Data/GlobalData");
var e = require;
var t = module;
var o = exports;
var n;
var Adv_skd=require("./Adv_skd");

function i(e, t) {
    return (i =
        Object.setPrototypeOf ||
        function (e, t) {
            return (e.__proto__ = t), e;
        })(e, t);
}

(o.__esModule = !0), (o.default = void 0);
var a = (function (e) {
    var t, o;

    function n() {
        var t;
        return (
            ((t = e.call(this) || this).bannerAd = null),
                (t.insterstitialAd = null),
                (t.rewardedVideoAd = null),
                (t.gameRecorderManager = null),
                (t.info = null),
                (t.bw = 0),
                (t.bh = 0),
                (t.btop = 0),
                (t.videoPath = null),
                (t.gameRecordStartTime = 0),
                (t.gameRecordStopTime = 0),
                (t.recordStartCb = null),
                (t.recordStopCb = null),
                (t.rewardedVideoTimeMax = 5e3),
                (t.rewardedVideoLoadTimeout = null),
                (t.rewardedVideoIsLoaded = !1),
                (t.moreGameBanner = null),
                (t.moreGameBtn = null),
                (t.followBtn = null),
                (t.env = null),
                t.init(),
                t
        );
    }

    (o = e), ((t = n).prototype = Object.create(o.prototype)), (t.prototype.constructor = t), i(t, o);
    var a = n.prototype;
    return (
        (a.init = function () {
            (this.env = tt),
                (this.info = (window.lplatform && lplatform.systemInfo) || this.env.getSystemInfoSync()),
                (this.bh = lplatform.cparam.bannerHeight || 170),
                (this.bw = lplatform.cparam.bannerWidth || Math.min(this.info.windowWidth, (16 * this.bh) / 9)),
                (this.gameRecorderManager = this.env.getGameRecorderManager());
        }),
            (a.initAD = function () {
                this.loadBanner(!1), this.loadInterstitial(!1), this.createRewardedVideo(!1);
            }),
            (a.checkOpenSceneValue = function () {
                var e = !0;
                if ("function" == typeof this.env.getLaunchOptionsSync) {
                    var t = this.env.getLaunchOptionsSync().scene;
                    console.log("sceneValue:" + t),
                        this.recordSceneValue(t),
                    (!lplatform.labData.openSceneValues || lplatform.labData.openSceneValues.indexOf(t) < 0) &&
                    (e = !1);
                }
                return e;
            }),
            (a.release = function () {
                this.hideBanner(!0),
                    this.hideInterstitial(),
                    this.hideRewardedVideo(),
                    this.hideLoading(),
                this.moreGameBanner && this.moreGameBanner.destroy(),
                this.followBtn && this.followBtn.destroy();
            }),
            (a.loadBanner = function (e) {
                this.hideBanner(!1),
                    (this.btop = 0),
                lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - this.bh),
                    lplatform.plog("loadBanner this.bh:" + this.bh + " this.btop:" + this.btop + " this.bw:" + this.bw),
                    (this.bannerAd = this.env.createBannerAd({
                        adUnitId: lplatform.cparam.bannerID,
                        adIntervals: 30,
                        style: {width: this.bw, left: (this.info.windowWidth - this.bw) / 2, top: this.btop}
                    })),
                    this.bannerAd.onLoad(this.onBannerLoad.bind(this)),
                    this.bannerAd.onError(this.onBannerError.bind(this)),
                    this.bannerAd.onResize(this.onBannerResize.bind(this)),
                    (this.bannerAutoShow = e),
                this.bannerAutoShow && this.bannerAd.show();
            }),
            (a.onBannerLoad = function () {
            }),
            (a.onBannerError = function (e, t) {
                lplatform.plog("onBannerError code:" + JSON.stringify(e) + " msg:" + t);
            }),
            (a.onBannerResize = function (e) {
                (this.btop = 0),
                lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - e.height),
                    (this.bannerAd.style.top = this.btop),
                    (this.bannerAd.style.left = (this.info.windowWidth - e.width) / 2),
                    lplatform.plog(
                        "onBannerResize this.bannerAd.style.top:" +
                        this.bannerAd.style.top +
                        " .left:" +
                        this.bannerAd.style.left +
                        " lplatform.cparam.bannerOnBottom:" +
                        lplatform.cparam.bannerOnBottom
                    );
            }),
            (a.showBanner = function () {
                this.bannerAd
                    ? this.bannerAd
                        .show()
                        .then(function () {
                        })
                        .catch(function (e) {
                            lplatform.plog(e);
                        })
                    : this.loadBanner(!0);
            }),
            (a.hideBanner = function (e) {
                void 0 === e && (e = !1),
                this.bannerAd &&
                (this.bannerAd.hide(),
                e &&
                (this.bannerAd.offLoad(this.onBannerLoad),
                    this.bannerAd.offError(this.onBannerError),
                    this.bannerAd.offResize(this.onBannerResize),
                    this.bannerAd.destroy(),
                    (this.bannerAd = null))),
                this.moreGameBanner &&
                (this.moreGameBanner.hide(),
                e && "function" == typeof this.moreGameBanner.destroy && this.moreGameBanner.destroy());
            }),
            (a.showCenterBanner = function () {
                if (!this.centerBanner) {
                    (this.btop = 0),
                    lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - this.bh),
                        (this.centerBanner = this.env.createBannerAd({
                            adUnitId: lplatform.cparam.bannerID,
                            adIntervals: 30,
                            style: {width: this.bw, height: this.bh, left: 0, top: this.btop}
                        }));
                    var e = this;
                    this.centerBanner.onLoad(function () {
                    }),
                        this.centerBanner.onError(function (e, t) {
                            lplatform.plog("centerBanner code:" + JSON.stringify(e) + " msg:" + t);
                        }),
                        this.centerBanner.onResize(function (t) {
                            (e.centerBanner.style.left = 0), (e.centerBanner.style.top = e.info.windowHeight - t.height);
                        });
                }
                this.centerBanner.show();
            }),
            (a.hideCenterBanner = function (e) {
                void 0 === e && (e = !1),
                this.centerBanner &&
                (this.centerBanner.hide(),
                e &&
                (this.centerBanner.offLoad(function () {
                }),
                    this.centerBanner.offError(function () {
                    }),
                    this.centerBanner.offResize(function () {
                    }),
                    this.centerBanner.destroy(),
                    (this.centerBanner = null)));
            }),
            (a.loadInterstitial = function (e) {
                this.hideInterstitial(),
                    (this.insterstitialAd = this.env.createInterstitialAd({adUnitId: ''})),
                    this.insterstitialAd.onLoad(this.onInterstitialLoad.bind(this)),
                    this.insterstitialAd.onError(this.onInterstitialError.bind(this)),
                    this.insterstitialAd.onClose(this.onInterstitialClose.bind(this)),
                    this.insterstitialAd.load(),
                e && this.showInterstitial();
            }),
            (a.onInterstitialLoad = function () {
            }),
            (a.onInterstitialError = function (e, t) {
                lplatform.plog("onInterstitialError code:" + e + " msg:" + t);
            }),
            (a.onInterstitialClose = function () {
                this.loadInterstitial(!1);
            }),
            (a.showInterstitial = function () {
                this.insterstitialAd ? this.insterstitialAd.show() : this.loadInterstitial(!0);
            }),
            (a.hideInterstitial = function () {
                this.insterstitialAd &&
                (this.insterstitialAd.offLoad(this.onInterstitialLoad),
                    this.insterstitialAd.offError(this.onInterstitialError),
                    this.insterstitialAd.offClose(this.onInterstitialClose),
                    this.insterstitialAd.destroy());
            }),
            (a.createRewardedVideo = function (e) {
                lplatform.cparam.rewardedVideoID &&
                (this.rewardedVideoAd ||
                "function" != typeof this.env.createRewardedVideoAd ||
                ((this.rewardedVideoAd = this.env.createRewardedVideoAd({
                    adUnitId: Adv_skd.default.instance.getAds().videoAdId
                })),
                    this.rewardedVideoAd.onError(this.onRewardedVideoError.bind(this)),
                    this.rewardedVideoAd.onClose(this.onRewardedVideoClose.bind(this)),
                    this.rewardedVideoAd.onLoad(this.onRewardedVideoLoad.bind(this))),
                e && this.showRewardedVideo(window.vcb));
            }),
            (a.loadRewardedVideo = function (e) {
                this.createRewardedVideo(e),
                    lplatform.plog("loadRewardedVideo this.rewardedVideoAd.load()"),
                    this.rewardedVideoAd.load();
            }),
            (a.onRewardedVideoLoad = function () {
                lplatform.plog("onRewardedVideoLoad this.rewardedVideoIAutoShow:" + this.rewardedVideoIAutoShow);
            }),
            (a.onRewardedVideoError = function (e, t) {
                lplatform.plog("onRewardedVideoError code:" + JSON.stringify(e) + " msg:" + t), this.resetRewardedVideo();
            }),
            (a.onRewardedVideoClose = function (e) {
                if ((lplatform.plog("onRewardedVideoClose res.isEnded:" + e.isEnded), e.isEnded))
                    window.vcb && window.vcb(e.isEnded), this.resetRewardedVideo(!1, !0), this.loadRewardedVideo(!1), HydSDK.PostClickId(GlobalData.event_type.game_addiction);

                else if (lplatform.labData.openSecondTipVideo) {
                    var t = this;
                    t.env.showModal({
                        title: "继续吗",
                        content: "观看完视频才能获得奖励哦",
                        success: function success(e) {
                            e.confirm
                                ? t.showRewardedVideo(window.vcb)
                                : e.cancel &&
                                (window.vcb && window.vcb(e.isEnded),
                                    this.resetRewardedVideo(!1, !0),
                                    this.loadRewardedVideo(!1));
                        }
                    });
                } else window.vcb && window.vcb(e.isEnded);
            }),
            (a.showRewardedVideo = function (e) {
                var t = this;
                e && (window.vcb = e),
                    this.rewardedVideoAd
                        ? (this.showLoading(),
                            (this.rewardedVideoLoadTimeout = setTimeout(
                                function () {
                                    lplatform.plog("rewardedVideoLoadTimeout 广告超时 timeMax:" + this.rewardedVideoTimeMax),
                                        clearTimeout(this.rewardedVideoLoadTimeout),
                                    window.vcb && window.vcb(!1, "广告超时"),
                                        this.resetRewardedVideo(!0, !0);
                                }.bind(this),
                                this.rewardedVideoTimeMax
                            )),
                            lplatform.plog("showRewardedVideo this.rewardedVideoIsLoaded:" + this.rewardedVideoIsLoaded),
                            this.rewardedVideoAd
                                .show()
                                .then(function () {
                                    lplatform.plog("showRewardedVideo then "),
                                        t.hideLoading(),
                                        clearTimeout(t.rewardedVideoLoadTimeout);
                                })
                                .catch(function (e) {
                                    lplatform.plog("showRewardedVideo catch:" + JSON.stringify(e)),
                                        t.hideLoading(),
                                        clearTimeout(t.rewardedVideoLoadTimeout),
                                        t.rewardedVideoAd
                                            .load()
                                            .then(function () {
                                                t.rewardedVideoAd.show();
                                            })
                                            .catch(function () {
                                                t.loadRewardedVideo(!1);
                                            });
                                }))
                        : this.createRewardedVideo(!0);
            }),
            (a.resetRewardedVideo = function (e, t) {
                void 0 === e && (e = !1),
                void 0 === t && (t = !1),
                this.rewardedVideoAd &&
                e &&
                (this.rewardedVideoAd.offLoad(this.onRewardedVideoLoad),
                    this.rewardedVideoAd.offError(this.onRewardedVideoError),
                    this.rewardedVideoAd.offClose(this.onRewardedVideoClose),
                    this.rewardedVideoAd.destroy(),
                    (this.rewardedVideoAd = null)),
                t && (window.vcb = null),
                this.rewardedVideoLoadTimeout && clearTimeout(this.rewardedVideoLoadTimeout),
                    this.hideLoading();
            }),
            (a.shareAppMessage = function () {
                this.env.shareAppMessage({
                    templateId: lplatform.cparam.shareID,
                    query: "",
                    success: function success() {
                    },
                    fail: function fail(e) {
                        lplatform.plog("分享失败:" + e);
                    }
                });
            }),
            (a.canRecord = function () {
                return !!this.gameRecorderManager;
            }),
            (a.canShareRecord = function () {
                return !!this.videoPath;
            }),
            (a.startRecord = function (e) {
                lplatform.plog("startRecord"),
                    (this.recordStartCb = e),
                    (this.videoPath = null),
                    this.gameRecorderManager.start({duration: 30}),
                    this.gameRecorderManager.onStart(this.onGameRecordStart.bind(this)),
                    this.gameRecorderManager.onError(this.onGameRecordError.bind(this)),
                    this.gameRecorderManager.onStop(this.onGameRecordStop.bind(this));
                var t = this;
                this.env.onShow(function () {
                    lplatform.plog("startRecord this.env.onShow"), t.resumeRecord();
                }),
                    this.env.onHide(function () {
                        lplatform.plog("startRecord this.env.onHide"), t.pauseRecord();
                    });
            }),
            (a.onGameRecordStart = function () {
                (this.gameRecordStartTime = Date.now()),
                this.recordStartCb && (this.recordStartCb(), (this.recordStartCb = null));
            }),
            (a.onGameRecordError = function (e) {
                lplatform.plog("onGameRecordError:" + e, "error");
            }),
            (a.onGameRecordStop = function (e) {
                lplatform.plog("onGameRecordStop this.recordStopCb:" + this.recordStopCb),
                    (this.gameRecordStopTime = Date.now()),
                    this.gameRecordStopTime - this.gameRecordStartTime > 4500
                        ? (this.videoPath = e.videoPath)
                        : (lplatform.plog("onGameRecordStop 实际录屏时间少于5秒就有可能分享失败"),
                            this.env.showToast({
                                title: "录制时间太短，可能无法分享。",
                                icon: "none",
                                duration: 1e3,
                                mask: !1,
                                success: function success() {
                                },
                                fail: function fail(e) {
                                    lplatform.plog(e);
                                }
                            })),
                this.recordStopCb && (this.recordStopCb(this.videoPath), (this.recordStopCb = null));
            }),
            (a.pauseRecord = function () {
                this.gameRecorderManager.pause();
            }),
            (a.resumeRecord = function () {
                this.gameRecorderManager.resume();
            }),
            (a.stopRecord = function (e) {
                lplatform.plog("stopRecord cb:" + e), (this.recordStopCb = e), this.gameRecorderManager.stop();
            }),
            (a.shareRecord = function (e, t) {
                if (this.videoPath) {
                    var o = this;
                    this.env.shareAppMessage({
                        channel: "video",
                        extra: {
                            videoPath: this.videoPath,
                            videoTopics: lplatform.cparam.videoTopics,
                            hashtag_list: lplatform.cparam.videoTopics,
                            createChallenge: !0
                        },
                        success: function success() {
                            (o.videoPath = null), e && e();
                        },
                        fail: function fail(e) {
                            var n = null,
                                i = JSON.stringify(e);
                            i.indexOf("cancel") >= 0
                                ? (n = "您取消了本次分享")
                                : i.indexOf("21105") >= 0 && (n = "视频太短，无法进行分享"),
                            n &&
                            o.env.showToast({
                                title: n,
                                icon: "none",
                                duration: 1e3,
                                mask: !1,
                                success: function success() {
                                },
                                fail: function fail(e) {
                                    lplatform.plog(e);
                                }
                            }),
                            t && t();
                        }
                    });
                } else
                    this.env.showToast({
                        title: "暂无可分享的视频",
                        icon: "none",
                        duration: 1e3,
                        mask: !1,
                        success: function success() {
                        },
                        fail: function fail(e) {
                            lplatform.plog(e);
                        }
                    }),
                    t && t();
            }),
            (a.resetRecord = function () {
                this.stopRecord(), (this.videoPath = null);
            }),
            (a.shareInnerRecord = function () {
            }),
            (a.createMoreGameButton = function () {
                (this.moreGameBtn = this.env.createMoreGamesButton({
                    type: "image",
                    image: "moreGame.png",
                    actionType: "box",
                    style: {
                        left: lplatform.cparam.moreGameLeft * lplatform.systemInfo.windowWidth,
                        top: lplatform.cparam.moreGameTop * lplatform.systemInfo.windowHeight,
                        width: 49.5,
                        height: 39.9,
                        lineHeight: 1,
                        backgroundColor: "#00000000",
                        textColor: "#ffffff",
                        textAlign: "center",
                        fontSize: 16,
                        borderRadius: 1,
                        borderWidth: 0,
                        borderColor: "#ff0000"
                    },
                    appLaunchOptions: [],
                    onNavigateToMiniGame: function onNavigateToMiniGame(e) {
                        lplatform.plog("跳转其他小游戏", e);
                    }
                })),
                    this.moreGameBtn.onTap(function () {
                        lplatform.plog("点击更多游戏");
                    });
            }),
            (a.showFavoriteGuide = function () {
                this.env.showFavoriteGuide({
                    type: "bar",
                    content: "一键加关注，从此不迷路!",
                    position: "bottom",
                    success: function success() {
                    },
                    fail: function fail(e) {
                        lplatform.plog("showFavoriteGuide fail:" + e);
                    }
                });
            }),
            (a.followAccount = function () {
                if ("function" == typeof this.env.checkFollowState) {
                    var e = this;
                    e.env.checkFollowState({
                        success: function success(t) {
                            t.errMsg && lplatform.plog("checkFollowState success, but has errMsg:" + t.errMsg),
                            t.result ||
                            (e.env.createFollowButton &&
                                (e.followBtn = e.env.createFollowButton({
                                    type: "image",
                                    image: "follow_btn.png",
                                    style: {
                                        left: lplatform.cparam.followBtnLeft * lplatform.systemInfo.windowWidth,
                                        top: lplatform.cparam.followBtnTop * lplatform.systemInfo.windowHeight,
                                        width: 49.5,
                                        height: 39.9,
                                        lineHeight: 40,
                                        backgroundColor: "#ff0000",
                                        textColor: "#ffffff",
                                        textAlign: "center",
                                        fontSize: 16,
                                        borderRadius: 4,
                                        borderWidth: 1,
                                        borderColor: "#ff0000"
                                    }
                                })));
                        },
                        fail: function fail(e) {
                            lplatform.plog("followAccount fail:" + e);
                        }
                    });
                } else "function" == typeof this.env.openAwemeUserProfile && this.env.openAwemeUserProfile();
            }),
            (a.goToGameOrGameList = function () {
                this.env.showMoreGamesModal({
                    appLaunchOptions: [],
                    success: function success(e) {
                        console.log("success", e.errMsg);
                    },
                    fail: function fail(e) {
                        console.log("fail", e.errMsg);
                    }
                });
            }),
            (a.openAwemeUserProfile = function () {
            }),
            (a.createMoreGameBanner = function () {
                if (lplatform.cparam.moreGameBannerAppId) {
                    var e = Math.floor(Math.random() * lplatform.cparam.moreGameBannerAppId.length),
                        t = lplatform.cparam.moreGameBannerAppId[e];
                    if (!this.moreGameBanner) {
                        (this.btop = 0),
                        lplatform.cparam.bannerOnBottom && (this.btop = this.info.windowHeight - 104),
                            (this.moreGameBanner = this.env.createMoreGamesBanner({
                                style: {width: 300, height: 104, left: 0, top: this.btop},
                                appLaunchOptions: [{appId: t, query: "foo=bar&baz=qux", extraData: {}}]
                            }));
                        var o = function o(e, t) {
                            lplatform.plog("监听事件:" + JSON.stringify(e) + " " + JSON.stringify(t));
                        };
                        this.moreGameBanner.onResize(
                            function (e) {
                                (this.moreGameBanner.style.top = this.info.windowHeight - 104),
                                    (this.moreGameBanner.style.left = (this.info.windowWidth - 300) / 2),
                                    lplatform.plog(
                                        "moreGameBanner size.width:" +
                                        e.width +
                                        " size.height:" +
                                        e.height +
                                        " lplatform.cparam.bannerOnBottom:" +
                                        lplatform.cparam.bannerOnBottom
                                    );
                            }.bind(this)
                        ),
                            this.moreGameBanner.onTap(o),
                            this.moreGameBanner.onError(o);
                    }
                    this.moreGameBanner.show(),
                    lplatform.cparam.moreGameBannerAutoCloseTime > 0 &&
                    setTimeout(
                        function () {
                            this.moreGameBanner.hide();
                        }.bind(this),
                        lplatform.cparam.moreGameBannerAutoCloseTime
                    );
                }
            }),
            (a.createMoreGamePortal = function () {
                "ios" !== this.info.platform
                    ? tt.showMoreGamesModal({
                        appLaunchOptions: [{appId: "ttXXXXXX", query: "foo=bar&baz=qux", extraData: {}}],
                        success: function success(e) {
                            console.log("success", e.errMsg);
                        },
                        fail: function fail(e) {
                            console.log("fail", e.errMsg);
                        }
                    })
                    : tt.showToast({title: " iOS不支持此功能"});
            }),
            (a.analytics = function (e, t) {
                "function" == typeof this.env.reportAnalytics && this.env.reportAnalytics(e, t);
            }),
            (a.showLoading = function (e) {
                this.hideLoading(),
                "function" == typeof this.env.showLoading &&
                this.env.showLoading({
                    title: e || "处理中，请稍候...",
                    success: function success() {
                    },
                    fail: function fail(e) {
                        lplatform.plog("showLoading调用失败:" + e);
                    }
                });
            }),
            (a.hideLoading = function () {
                var e = this;
                "function" == typeof this.env.hideLoading &&
                this.env.hideLoading({
                    success: function success() {
                    },
                    fail: function fail(t) {
                        lplatform.plog("hideLoading调用失败:" + t),
                            setTimeout(
                                function () {
                                    e.env.hideLoading({
                                        success: function success() {
                                        },
                                        fail: function fail(e) {
                                            lplatform.plog("hideLoading二次调用失败:" + e);
                                        }
                                    });
                                }.bind(this),
                                1e3
                            );
                    },
                    complete: function complete() {
                    }
                });
            }),
            (a.createGameClub = function () {
            }),
            (a.navigateToMiniProgram = function () {
            }),
            (a.shareMessageToFriend = function () {
            }),
            (a.sendMsgToOpenDataProject = function () {
            }),
            (a.makeShareUI = function (e, t, o, n, i) {
                void 0 === n && (n = 0),
                void 0 === i && (i = !1),
                    lplatform.uiEngine.CreateShareK(
                        function () {
                            this.shareRecord(e, t);
                        }.bind(this),
                        function () {
                            t && t();
                        }.bind(this),
                        o,
                        n,
                        i
                    );
            }),
            (a.httpRequest = function (e, t, o, n, i) {
                var a = new XMLHttpRequest();
                (a.timeout = o),
                    (a.onreadystatechange = function () {
                        4 == a.readyState &&
                        (a.status >= 200 && a.status < 400
                            ? t(null, a.response, a.responseText)
                            : t(a.status, null, null));
                    }),
                    a.open(n || "GET", e, !0),
                    a.send(i);
            }),
            (a.recordSceneValue = function (e) {
                lplatform.labData.recordSceneValue &&
                this.env.request({
                    url: "https://lab.bwyxa.com/api/userinfo",
                    data: {sceneValue: e},
                    header: {"content-type": "application/json"},
                    success: function success() {
                    },
                    fail: function fail() {
                    }
                });
            }),
            n
    );
})(((n = e("PDef")) && n.__esModule ? n : {default: n}).default);
(o.default = a), (t.exports = o.default);
